# 1.字典(键值对的形式，可以根据键拿到对应的值)
d1 = {'color': 'green', 'points': 5}
print(d1['color'])
print(d1['points'])


# 2.添加键值对
d1['y'] = 5
d1['x'] = 10
print(d1)

# 3.修改字典元素的值
d1['color'] = 'red'
print(d1)


# 4.删除键值对
del d1['points']
print(d1)


# 5.遍历字典
for key, value in d1.items():
    print(str(key) + ': ' + str(value))


# 6.遍历字典中的所有键
for key in d1.keys():
    print(str(key))


# 7.按顺序遍历字典中的所有键
for key in sorted(d1.keys()):
    print(str(key))


# 8.遍历字典中的所有值
for value in d1.values():
    print(value)


# 9.在字典中存储列表
pizza = {
 'crust': 'thick',
 'toppings': ['mushrooms', 'extra cheese'],
 }
print("\t" + pizza['crust'])
for topping in pizza['toppings']:
    print("\t" + topping)

# 10.在字典中存储字典
users = {
 'aeinstein': {
 'first': 'albert',
 'last': 'einstein',
 'location': 'princeton',
 },
 'mcurie': {
 'first': 'marie',
 'last': 'curie',
 'location': 'paris',
 },
 }
for username, user_info in users.items():
    print("\nUsername: " + username)
    full_name = user_info['first'] + " " + user_info['last']
    location = user_info['location']
    print("\tFull name: " + full_name.title())
    print("\tLocation: " + location.title())